package com.dodayum.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dodayum.entity.DemoTableEntity;
import com.dodayum.mapper.DemoTableMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version 1.0
 * 备注：
 * @Author BaiYu
 * </br>@Date 2025/1/14 15:07
 */

@Service
public class DemoTableService {

    @Resource
    private DemoTableMapper demoTableMapper;

    public void insert(DemoTableEntity demoTableEntity){
        demoTableMapper.insert(demoTableEntity);
    }

    public void deleteById(String id) {
        demoTableMapper.deleteById(id);
    }

    public DemoTableEntity updateById(DemoTableService demoTableService) {
        return demoTableService.updateById(demoTableService);
    }

    public List<DemoTableEntity> query(DemoTableEntity demoTableEntity) {



        LambdaQueryWrapper<DemoTableEntity> demoTableEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        demoTableEntityLambdaQueryWrapper
                .eq(StringUtils.isNotBlank(demoTableEntity.getId()),DemoTableEntity::getId, demoTableEntity.getId())
                .eq(StringUtils.isNotBlank(demoTableEntity.getName()),DemoTableEntity::getName, demoTableEntity.getName())
                .eq(!ObjectUtils.isEmpty(demoTableEntity.getAge()),DemoTableEntity::getAge, demoTableEntity.getAge())
                .eq(StringUtils.isNotBlank(demoTableEntity.getContent()),DemoTableEntity::getContent, demoTableEntity.getContent());
        return demoTableMapper.selectList(demoTableEntityLambdaQueryWrapper);
    }

    public Long queryCount(){
        return demoTableMapper.selectCount(new LambdaQueryWrapper<>());
    }




}
